
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>9、dockerfile · 王坤个人博客</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="wk">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-duotone-dark.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="10、创建自己的tomcat镜像.html" />
    
    
    <link rel="prev" href="8、容器数据卷-持久化文件或目录.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://my.oschina.net/kunBlog" target="_blank" class="custom-link">我的博客地址</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../cassandra/">
            
                <a href="../cassandra/">
            
                    
                    Cassandra
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../cassandra/1、cassandra的安装.html">
            
                <a href="../cassandra/1、cassandra的安装.html">
            
                    
                    1、cassandra的安装
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="1、docker与虚拟机的不同.html">
            
                <a href="1、docker与虚拟机的不同.html">
            
                    
                    1、docker与虚拟机的不同
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="2、镜像、容器、仓库.html">
            
                <a href="2、镜像、容器、仓库.html">
            
                    
                    2、镜像、容器、仓库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="3、在centos中安装.html">
            
                <a href="3、在centos中安装.html">
            
                    
                    3、在centos中安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="4、配置私有镜像仓库.html">
            
                <a href="4、配置私有镜像仓库.html">
            
                    
                    4、配置私有镜像仓库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="5、docker的命令.html">
            
                <a href="5、docker的命令.html">
            
                    
                    5、docker的命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="6、镜像的原理.html">
            
                <a href="6、镜像的原理.html">
            
                    
                    6、镜像的原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="7、创建一个镜像.html">
            
                <a href="7、创建一个镜像.html">
            
                    
                    7、创建一个镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="8、容器数据卷-持久化文件或目录.html">
            
                <a href="8、容器数据卷-持久化文件或目录.html">
            
                    
                    8、容器数据卷(持久化文件或目录)
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.9" data-path="9、dockerfile.html">
            
                <a href="9、dockerfile.html">
            
                    
                    9、dockerfile
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="10、创建自己的tomcat镜像.html">
            
                <a href="10、创建自己的tomcat镜像.html">
            
                    
                    10、创建自己的tomcat镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="11、使用docker安装mysql和redis.html">
            
                <a href="11、使用docker安装mysql和redis.html">
            
                    
                    11、使用docker安装mysql和redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="12、把本地镜像发布到阿里云.html">
            
                <a href="12、把本地镜像发布到阿里云.html">
            
                    
                    12、把本地镜像发布到阿里云
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../golang/">
            
                <a href="../golang/">
            
                    
                    Golang
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" >
            
                <span>
            
                    
                    Examples
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1.1" data-path="../golang/examples/1、生成随机数.html">
            
                <a href="../golang/examples/1、生成随机数.html">
            
                    
                    1、生成随机数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.2" data-path="../golang/examples/2、数组冒泡排序.html">
            
                <a href="../golang/examples/2、数组冒泡排序.html">
            
                    
                    2、数组冒泡排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.3" data-path="../golang/examples/3、二分查找.html">
            
                <a href="../golang/examples/3、二分查找.html">
            
                    
                    3、二分查找
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.4" data-path="../golang/examples/4、工厂模式.html">
            
                <a href="../golang/examples/4、工厂模式.html">
            
                    
                    4、工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.5" data-path="../golang/examples/5、对切片排序.html">
            
                <a href="../golang/examples/5、对切片排序.html">
            
                    
                    5、对切片排序
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.2" >
            
                <span>
            
                    
                    go的命令行
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.2.1" data-path="../golang/go的命令行/1、go的get命令.html">
            
                <a href="../golang/go的命令行/1、go的get命令.html">
            
                    
                    1、go get 命令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.3" >
            
                <span>
            
                    
                    json序列化
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.3.1" data-path="../golang/json序列化/1、json序列化.html">
            
                <a href="../golang/json序列化/1、json序列化.html">
            
                    
                    1、json序列化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3.2" data-path="../golang/json序列化/2、json反序列化.html">
            
                <a href="../golang/json序列化/2、json反序列化.html">
            
                    
                    2、json反序列化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.4" >
            
                <span>
            
                    
                    包管理工具
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.4.1" data-path="../golang/包管理工具/dep包管理工具.html">
            
                <a href="../golang/包管理工具/dep包管理工具.html">
            
                    
                    dep包管理工具
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.5" >
            
                <span>
            
                    
                    协程和管道
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.5.1" data-path="../golang/协程和管道/1、goroutine基础.html">
            
                <a href="../golang/协程和管道/1、goroutine基础.html">
            
                    
                    1、goroutine基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.2" data-path="../golang/协程和管道/2、goroutine的调度模型.html">
            
                <a href="../golang/协程和管道/2、goroutine的调度模型.html">
            
                    
                    2、goroutine的调度模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.3" data-path="../golang/协程和管道/3、全局锁和管道.html">
            
                <a href="../golang/协程和管道/3、全局锁和管道.html">
            
                    
                    3、全局锁和管道
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.4" data-path="../golang/协程和管道/4、管道.html">
            
                <a href="../golang/协程和管道/4、管道.html">
            
                    
                    4、管道
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5.5" data-path="../golang/协程和管道/5、管道的注意点.html">
            
                <a href="../golang/协程和管道/5、管道的注意点.html">
            
                    
                    5、管道的注意点
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.6" >
            
                <span>
            
                    
                    单元测试
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.6.1" data-path="../golang/单元测试/1、单元测试入门.html">
            
                <a href="../golang/单元测试/1、单元测试入门.html">
            
                    
                    1、单元测试入门
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.7" >
            
                <span>
            
                    
                    反射
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.7.1" data-path="../golang/反射/1、反射.html">
            
                <a href="../golang/反射/1、反射.html">
            
                    
                    1、反射
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7.2" data-path="../golang/反射/2、反射的使用细节.html">
            
                <a href="../golang/反射/2、反射的使用细节.html">
            
                    
                    2、反射的使用细节
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.8" >
            
                <span>
            
                    
                    常量
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.8.1" data-path="../golang/常量/1、常量.html">
            
                <a href="../golang/常量/1、常量.html">
            
                    
                    1、常量
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.9" >
            
                <span>
            
                    
                    文件操作
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.9.1" data-path="../golang/文件操作/1、读取文件.html">
            
                <a href="../golang/文件操作/1、读取文件.html">
            
                    
                    1、读取文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9.2" data-path="../golang/文件操作/2、写文件.html">
            
                <a href="../golang/文件操作/2、写文件.html">
            
                    
                    2、写文件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.10" >
            
                <span>
            
                    
                    网络编程
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.10.1" data-path="../golang/网络编程/1、网络编程基础.html">
            
                <a href="../golang/网络编程/1、网络编程基础.html">
            
                    
                    1、网络编程基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.11" >
            
                <span>
            
                    
                    面向对象
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.11.1" data-path="../golang/面向对象/1、go使用struct实现OOP.html">
            
                <a href="../golang/面向对象/1、go使用struct实现OOP.html">
            
                    
                    1、go使用struct实现OOP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.2" data-path="../golang/面向对象/2、方法.html">
            
                <a href="../golang/面向对象/2、方法.html">
            
                    
                    2、方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.3" data-path="../golang/面向对象/3、封装.html">
            
                <a href="../golang/面向对象/3、封装.html">
            
                    
                    3、封装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.4" data-path="../golang/面向对象/4、继承.html">
            
                <a href="../golang/面向对象/4、继承.html">
            
                    
                    4、继承
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.5" data-path="../golang/面向对象/5、接口.html">
            
                <a href="../golang/面向对象/5、接口.html">
            
                    
                    5、接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.6" data-path="../golang/面向对象/6、多肽.html">
            
                <a href="../golang/面向对象/6、多肽.html">
            
                    
                    6、多肽
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11.7" data-path="../golang/面向对象/7、类型断言.html">
            
                <a href="../golang/面向对象/7、类型断言.html">
            
                    
                    7、类型断言
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.12" data-path="../golang/1、windows下安装golang环境.html">
            
                <a href="../golang/1、windows下安装golang环境.html">
            
                    
                    1、windows下安装golang环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.13" data-path="../golang/2、webStorm安装go语言插件.html">
            
                <a href="../golang/2、webStorm安装go语言插件.html">
            
                    
                    2、webStorm安装go语言插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.14" data-path="../golang/3、go的一些语法风格.html">
            
                <a href="../golang/3、go的一些语法风格.html">
            
                    
                    3、go的一些语法风格
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.15" data-path="../golang/4、go语法-变量.html">
            
                <a href="../golang/4、go语法-变量.html">
            
                    
                    4、go语法-变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.16" data-path="../golang/5、go语法--数据类型.html">
            
                <a href="../golang/5、go语法--数据类型.html">
            
                    
                    5、go语法--数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.17" data-path="../golang/6、go的整数类型.html">
            
                <a href="../golang/6、go的整数类型.html">
            
                    
                    6、go的整数类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.18" data-path="../golang/7、go的浮点类型.html">
            
                <a href="../golang/7、go的浮点类型.html">
            
                    
                    7、go的浮点类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.19" data-path="../golang/8、go的字符类型.html">
            
                <a href="../golang/8、go的字符类型.html">
            
                    
                    8、go的字符类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.20" data-path="../golang/9、go的bool类型.html">
            
                <a href="../golang/9、go的bool类型.html">
            
                    
                    9、go的bool类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.21" data-path="../golang/10、go的string类型.html">
            
                <a href="../golang/10、go的string类型.html">
            
                    
                    10、go的string类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.22" data-path="../golang/11、基本数据类型相互转换.html">
            
                <a href="../golang/11、基本数据类型相互转换.html">
            
                    
                    11、基本数据类型相互转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.23" data-path="../golang/12、基本数据类型和string的转换.html">
            
                <a href="../golang/12、基本数据类型和string的转换.html">
            
                    
                    12、基本数据类型和string的转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.24" data-path="../golang/13、go的指针.html">
            
                <a href="../golang/13、go的指针.html">
            
                    
                    13、go的指针
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.25" data-path="../golang/14、go的标识符.html">
            
                <a href="../golang/14、go的标识符.html">
            
                    
                    14、go的标识符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.26" data-path="../golang/15、go的关键字.html">
            
                <a href="../golang/15、go的关键字.html">
            
                    
                    15、go的关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.27" data-path="../golang/16、go的运算符-算术运算.html">
            
                <a href="../golang/16、go的运算符-算术运算.html">
            
                    
                    16、go的运算符-算术运算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.28" data-path="../golang/17、比较、赋值、逻辑运算符.html">
            
                <a href="../golang/17、比较、赋值、逻辑运算符.html">
            
                    
                    17、比较、赋值、逻辑运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.29" data-path="../golang/18、运算符的优先级.html">
            
                <a href="../golang/18、运算符的优先级.html">
            
                    
                    18、运算符的优先级
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.30" data-path="../golang/19、其他运算符.html">
            
                <a href="../golang/19、其他运算符.html">
            
                    
                    19、其他运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.31" data-path="../golang/20、go获取键盘输入.html">
            
                <a href="../golang/20、go获取键盘输入.html">
            
                    
                    20、go获取键盘输入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.32" data-path="../golang/21、进制、位运算.html">
            
                <a href="../golang/21、进制、位运算.html">
            
                    
                    21、进制、位运算
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.33" data-path="../golang/22、if和switch语句.html">
            
                <a href="../golang/22、if和switch语句.html">
            
                    
                    22、if和switch语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.34" data-path="../golang/23、for循环.html">
            
                <a href="../golang/23、for循环.html">
            
                    
                    23、for循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.35" data-path="../golang/24、goto语句.html">
            
                <a href="../golang/24、goto语句.html">
            
                    
                    24、goto语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.36" data-path="../golang/25、函数1.html">
            
                <a href="../golang/25、函数1.html">
            
                    
                    25、函数1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.37" data-path="../golang/26、包-package.html">
            
                <a href="../golang/26、包-package.html">
            
                    
                    26、包-package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.38" data-path="../golang/27、init函数.html">
            
                <a href="../golang/27、init函数.html">
            
                    
                    27、init函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.39" data-path="../golang/28、匿名函数.html">
            
                <a href="../golang/28、匿名函数.html">
            
                    
                    28、匿名函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.40" data-path="../golang/29、闭包.html">
            
                <a href="../golang/29、闭包.html">
            
                    
                    29、闭包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.41" data-path="../golang/30、defer.html">
            
                <a href="../golang/30、defer.html">
            
                    
                    30、defer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.42" data-path="../golang/31、值传递和引用传递.html">
            
                <a href="../golang/31、值传递和引用传递.html">
            
                    
                    31、值传递和引用传递
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.43" data-path="../golang/32、常用字符串函数.html">
            
                <a href="../golang/32、常用字符串函数.html">
            
                    
                    32、常用字符串函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.44" data-path="../golang/33、时间和日期函数.html">
            
                <a href="../golang/33、时间和日期函数.html">
            
                    
                    33、时间和日期函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.45" data-path="../golang/34、go语言的内置函数.html">
            
                <a href="../golang/34、go语言的内置函数.html">
            
                    
                    34、go语言的内置函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.46" data-path="../golang/35、go语言的错误处理.html">
            
                <a href="../golang/35、go语言的错误处理.html">
            
                    
                    35、go语言的错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.47" data-path="../golang/36、数组.html">
            
                <a href="../golang/36、数组.html">
            
                    
                    36、数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.48" data-path="../golang/37、切片slice.html">
            
                <a href="../golang/37、切片slice.html">
            
                    
                    37、切片slice
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.49" data-path="../golang/38、string和slice.html">
            
                <a href="../golang/38、string和slice.html">
            
                    
                    38、string 和 slice
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.50" data-path="../golang/39、二维数组.html">
            
                <a href="../golang/39、二维数组.html">
            
                    
                    39、二维数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.51" data-path="../golang/40、map的用法.html">
            
                <a href="../golang/40、map的用法.html">
            
                    
                    40、map的用法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.52" data-path="../golang/41、获取命令行参数.html">
            
                <a href="../golang/41、获取命令行参数.html">
            
                    
                    41、获取命令行参数
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../Istio/">
            
                <a href="../Istio/">
            
                    
                    Istio
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../redis/">
            
                <a href="../redis/">
            
                    
                    Redis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" >
            
                <span>
            
                    
                    golang连接redis
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1.1" data-path="../redis/golang连接redis/1、go语言连接使用redis.html">
            
                <a href="../redis/golang连接redis/1、go语言连接使用redis.html">
            
                    
                    1、go语言连接使用redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.1.2" data-path="../redis/golang连接redis/2、redis连接池.html">
            
                <a href="../redis/golang连接redis/2、redis连接池.html">
            
                    
                    2、redis连接池
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.2" >
            
                <span>
            
                    
                    protected-mode设置
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.2.1" data-path="../redis/protected-mode设置/1、设置保护模式.html">
            
                <a href="../redis/protected-mode设置/1、设置保护模式.html">
            
                    
                    1、设置保护模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../redis/1、redis的安装.html">
            
                <a href="../redis/1、redis的安装.html">
            
                    
                    1、redis的安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../redis/2、redis数据库的命令操作.html">
            
                <a href="../redis/2、redis数据库的命令操作.html">
            
                    
                    2、redis数据库的命令操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../redis/3、string类型的操作.html">
            
                <a href="../redis/3、string类型的操作.html">
            
                    
                    3、string类型的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../redis/4、hash类型的操作.html">
            
                <a href="../redis/4、hash类型的操作.html">
            
                    
                    4、hash类型的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../redis/5、list类型的操作.html">
            
                <a href="../redis/5、list类型的操作.html">
            
                    
                    5、list类型的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../redis/6、Set类型的操作.html">
            
                <a href="../redis/6、Set类型的操作.html">
            
                    
                    6、Set类型的操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../redis/7、docker安装redis.html">
            
                <a href="../redis/7、docker安装redis.html">
            
                    
                    7、docker安装redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../redis/8、redis集群搭建.html">
            
                <a href="../redis/8、redis集群搭建.html">
            
                    
                    8、redis集群搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../redis/9、zset类型的操作.html">
            
                <a href="../redis/9、zset类型的操作.html">
            
                    
                    9、zset类型的操作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <span>
            
                    
                    数据结构和算法
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../数据结构和算法/1、稀疏数组.html">
            
                <a href="../数据结构和算法/1、稀疏数组.html">
            
                    
                    1、稀疏数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../数据结构和算法/2、队列.html">
            
                <a href="../数据结构和算法/2、队列.html">
            
                    
                    2、队列
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../数据结构和算法/3、单向链表.html">
            
                <a href="../数据结构和算法/3、单向链表.html">
            
                    
                    3、单向链表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../数据结构和算法/4、双向链表.html">
            
                <a href="../数据结构和算法/4、双向链表.html">
            
                    
                    4、双向链表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../数据结构和算法/5、单向环形链表.html">
            
                <a href="../数据结构和算法/5、单向环形链表.html">
            
                    
                    5、单向环形链表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../数据结构和算法/6、约瑟夫问题.html">
            
                <a href="../数据结构和算法/6、约瑟夫问题.html">
            
                    
                    6、约瑟夫问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../数据结构和算法/7、选择排序.html">
            
                <a href="../数据结构和算法/7、选择排序.html">
            
                    
                    7、选择排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../数据结构和算法/8、插入排序.html">
            
                <a href="../数据结构和算法/8、插入排序.html">
            
                    
                    8、插入排序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../数据结构和算法/9、快速排序法.html">
            
                <a href="../数据结构和算法/9、快速排序法.html">
            
                    
                    9、快速排序法
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../springCloud/">
            
                <a href="../springCloud/">
            
                    
                    springCloud
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../springCloud/consul/">
            
                <a href="../springCloud/consul/">
            
                    
                    consul
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1.1" data-path="../springCloud/consul/1、springcloud服务注册到consul.html">
            
                <a href="../springCloud/consul/1、springcloud服务注册到consul.html">
            
                    
                    1、springcloud服务注册到consul
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.1.2" data-path="../springCloud/consul/2、springcloud消费consul中注册的服务.html">
            
                <a href="../springCloud/consul/2、springcloud消费consul中注册的服务.html">
            
                    
                    2、springcloud消费consul中注册的服务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.1.3" data-path="../springCloud/consul/3、springcloud使用consul做配置中心.html">
            
                <a href="../springCloud/consul/3、springcloud使用consul做配置中心.html">
            
                    
                    3、springcloud使用consul做配置中心
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../springCloud/springBoot/">
            
                <a href="../springCloud/springBoot/">
            
                    
                    springBoot
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.2.1" >
            
                <span>
            
                    
                    一些问题解决方式
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.2.1.1" data-path="../springCloud/springBoot/一些问题解决方式/1、StreamingResponseBody问题.html">
            
                <a href="../springCloud/springBoot/一些问题解决方式/1、StreamingResponseBody问题.html">
            
                    
                    1、StreamingResponseBody问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8.2.2" data-path="../springCloud/springBoot/1、新建springboot工程.html">
            
                <a href="../springCloud/springBoot/1、新建springboot工程.html">
            
                    
                    1、新建springboot工程
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../springCloud/1、Eureka服务注册中心.html">
            
                <a href="../springCloud/1、Eureka服务注册中心.html">
            
                    
                    1、Eureka服务注册中心
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../springCloud/2、服务调用.html">
            
                <a href="../springCloud/2、服务调用.html">
            
                    
                    2、服务调用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../springCloud/3、断路器hystrix的使用.html">
            
                <a href="../springCloud/3、断路器hystrix的使用.html">
            
                    
                    3、断路器hystrix的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../springCloud/4、断路器hystrix的隔离策略.html">
            
                <a href="../springCloud/4、断路器hystrix的隔离策略.html">
            
                    
                    4、断路器hystrix的隔离策略
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../springCloud/5、hystrix的Dashboard和Turbine.html">
            
                <a href="../springCloud/5、hystrix的Dashboard和Turbine.html">
            
                    
                    5、hystrix的Dashboard和Turbine
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../vpn/">
            
                <a href="../vpn/">
            
                    
                    Vpn
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../vpn/1、ss服务器的安装.html">
            
                <a href="../vpn/1、ss服务器的安装.html">
            
                    
                    1、ss服务器的安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../vpn/2、SS客户端.html">
            
                <a href="../vpn/2、SS客户端.html">
            
                    
                    2、SS客户端
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" >
            
                <span>
            
                    
                    gitbook的使用
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../gitbook的使用/1、gitbook的使用.html">
            
                <a href="../gitbook的使用/1、gitbook的使用.html">
            
                    
                    1、gitbook 的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../gitbook的使用/2、gitbook命令.html">
            
                <a href="../gitbook的使用/2、gitbook命令.html">
            
                    
                    2、gitbook命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../gitbook的使用/3、gitbook连续大括号的解决方式.html">
            
                <a href="../gitbook的使用/3、gitbook连续大括号的解决方式.html">
            
                    
                    3、gitbook连续大括号的解决方式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../gitbook的使用/4、gitbook插件.html">
            
                <a href="../gitbook的使用/4、gitbook插件.html">
            
                    
                    4、gitbook插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../gitbook的使用/5、去掉-本书由gitbook发布.html">
            
                <a href="../gitbook的使用/5、去掉-本书由gitbook发布.html">
            
                    
                    5、去掉-本书由gitbook发布
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" >
            
                <span>
            
                    
                    markdown学习
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../markdown学习/1、markdown的学习.html">
            
                <a href="../markdown学习/1、markdown的学习.html">
            
                    
                    1、markdown的学习
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../keycloak/">
            
                <a href="../keycloak/">
            
                    
                    keycloak
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../keycloak/1、keycloak的简单使用.html">
            
                <a href="../keycloak/1、keycloak的简单使用.html">
            
                    
                    1、keycloak的简单使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" >
            
                <span>
            
                    
                    分布式事务
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../分布式事务/1、事务的介绍.html">
            
                <a href="../分布式事务/1、事务的介绍.html">
            
                    
                    1、事务的介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../分布式事务/2、分布式事务的理论.html">
            
                <a href="../分布式事务/2、分布式事务的理论.html">
            
                    
                    2、分布式事务的理论
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >9、dockerfile</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#dockerfile-&#x662F;&#x4EC0;&#x4E48;&#x3002;"><b>1. </b>Dockerfile &#x662F;&#x4EC0;&#x4E48;&#x3002;</a></li><li><span class="title-icon "></span><a href="#dockerfile-&#x7684;&#x4F5C;&#x7528;&#x3002;"><b>2. </b>Dockerfile &#x7684;&#x4F5C;&#x7528;&#x3002;</a></li><li><span class="title-icon "></span><a href="#dockerfile&#x7684;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x3002;"><b>3. </b>Dockerfile&#x7684;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x3002;</a></li><li><span class="title-icon "></span><a href="#dockerfile&#x7684;&#x4E00;&#x4E9B;&#x89C4;&#x8303;&#x3002;"><b>4. </b>Dockerfile&#x7684;&#x4E00;&#x4E9B;&#x89C4;&#x8303;&#x3002;</a></li><li><span class="title-icon "></span><a href="#docker-build-&#x6267;&#x884C;dockerfile&#x7684;&#x5927;&#x81F4;&#x6D41;&#x7A0B;&#x3002;"><b>5. </b>Docker build &#x6267;&#x884C;Dockerfile&#x7684;&#x5927;&#x81F4;&#x6D41;&#x7A0B;&#x3002;</a></li><li><span class="title-icon "></span><a href="#dockerfile&#x7684;&#x4E00;&#x4E9B;&#x4FDD;&#x7559;&#x5B57;&#x6307;&#x4EE4;&#x3002;"><b>6. </b>Dockerfile&#x7684;&#x4E00;&#x4E9B;&#x4FDD;&#x7559;&#x5B57;&#x6307;&#x4EE4;&#x3002;</a></li><ul><li><span class="title-icon "></span><a href="#&#x4F8B;&#x5B50;1&#xFF1A;&#x4F7F;&#x7528;dockerfile&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;centos&#x955C;&#x50CF;&#x3002;"><b>6.1. </b>&#x4F8B;&#x5B50;1&#xFF1A;&#x4F7F;&#x7528;Dockerfile&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;centos&#x955C;&#x50CF;&#x3002;</a></li><li><span class="title-icon "></span><a href="#&#x4F8B;&#x5B50;2&#xFF1A;&#x67E5;&#x770B;&#x955C;&#x50CF;&#x7684;&#x53D8;&#x66F4;&#x5386;&#x53F2;&#x3002;"><b>6.2. </b>&#x4F8B;&#x5B50;2&#xFF1A;&#x67E5;&#x770B;&#x955C;&#x50CF;&#x7684;&#x53D8;&#x66F4;&#x5386;&#x53F2;&#x3002;</a></li><li><span class="title-icon "></span><a href="#cmdentrypoint&#x6307;&#x4EE4;&#x7684;&#x533A;&#x522B;&#x3002;"><b>6.3. </b>CMD/ENTRYPOINT&#x6307;&#x4EE4;&#x7684;&#x533A;&#x522B;&#x3002;</a></li><ul><li><span class="title-icon "></span><a href="#&#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;"><b>6.3.1. </b>&#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</a></li></ul></ul></ul></div><a href="#dockerfile-&#x662F;&#x4EC0;&#x4E48;&#x3002;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="dockerfile-&#x662F;&#x4EC0;&#x4E48;&#x3002;"><a name="dockerfile-&#x662F;&#x4EC0;&#x4E48;&#x3002;" class="anchor-navigation-ex-anchor" href="#dockerfile-&#x662F;&#x4EC0;&#x4E48;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>1. Dockerfile &#x662F;&#x4EC0;&#x4E48;&#x3002;</h1>
<p>Dockerfile&#x662F;&#x7528;&#x6765;&#x6784;&#x5EFA;Docker&#x955C;&#x50CF;&#x7684;&#x6784;&#x5EFA;&#x6587;&#x4EF6;&#xFF0C;&#x662F;&#x7531;&#x4E00;&#x7CFB;&#x5217;&#x547D;&#x4EE4;&#x548C;&#x53C2;&#x6570;&#x6784;&#x6210;&#x7684;&#x811A;&#x672C;&#x6587;&#x4EF6;&#x3002;</p>
<h1 id="dockerfile-&#x7684;&#x4F5C;&#x7528;&#x3002;"><a name="dockerfile-&#x7684;&#x4F5C;&#x7528;&#x3002;" class="anchor-navigation-ex-anchor" href="#dockerfile-&#x7684;&#x4F5C;&#x7528;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>2. Dockerfile &#x7684;&#x4F5C;&#x7528;&#x3002;</h1>
<p>&#x4F7F;&#x7528; docker build &#x547D;&#x4EE4;&#x6307;&#x5B9A;Dockerfile &#xFF0C;&#x53EF;&#x4EE5;&#x6839;&#x636E;Dockerfile&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x955C;&#x50CF;&#x3002;</p>
<p>Dockerfile&#x6D89;&#x53CA;&#x7684;&#x5185;&#x5BB9;&#x5305;&#x62EC;&#x6267;&#x884C;&#x4EE3;&#x7801;&#x6216;&#x8005;&#x662F;&#x6587;&#x4EF6;&#x3001;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x3001;&#x4F9D;&#x8D56;&#x5305;&#x3001;&#x8FD0;&#x884C;&#x65F6;&#x73AF;&#x5883;&#x3001;&#x52A8;&#x6001;&#x94FE;&#x63A5;&#x5E93;&#x3001;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x7684;&#x53D1;&#x884C;&#x7248;&#x3001;&#x670D;&#x52A1;&#x8FDB;&#x7A0B;&#x548C;&#x5185;&#x6838;&#x8FDB;&#x7A0B;(&#x5F53;&#x5E94;&#x7528;&#x8FDB;&#x7A0B;&#x9700;&#x8981;&#x548C;&#x7CFB;&#x7EDF;&#x670D;&#x52A1;&#x548C;&#x5185;&#x6838;&#x8FDB;&#x7A0B;&#x6253;&#x4EA4;&#x9053;&#xFF0C;&#x8FD9;&#x65F6;&#x9700;&#x8981;&#x8003;&#x8651;&#x5982;&#x4F55;&#x8BBE;&#x8BA1;namespace&#x7684;&#x6743;&#x9650;&#x63A7;&#x5236;)&#x7B49;&#x7B49;;</p>
<h1 id="dockerfile&#x7684;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x3002;"><a name="dockerfile&#x7684;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x3002;" class="anchor-navigation-ex-anchor" href="#dockerfile&#x7684;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>3. Dockerfile&#x7684;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x3002;</h1>
<p>centos&#x7684;docker&#x955C;&#x50CF;&#x5730;&#x5740; hub.docker.com/_/centos/ &#x53EF;&#x4EE5;&#x5728;&#x4E0A;&#x9762;&#x770B;&#x5230;&#x6784;&#x5EFA;centos&#x955C;&#x50CF;&#x7684;Dockerfile&#x3002;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code>FROM scratch
ADD centos-7-docker.tar.xz /

LABEL org.label-schema.schema-version=&quot;1.0&quot; \
    org.label-schema.name=&quot;CentOS Base Image&quot; \
    org.label-schema.vendor=&quot;CentOS&quot; \
    org.label-schema.license=&quot;GPLv2&quot; \
    org.label-schema.build-date=&quot;20181205&quot;

CMD [&quot;/bin/bash&quot;]
</code></pre><p>centos&#x955C;&#x50CF;&#x7684;Dockerfile&#x91CC;&#x9762;&#x6709;&#x4E00;&#x4E2A; <strong>FROM scratch</strong> &#x6307;&#x4EE4;<strong>&#xFF0C;scratch&#x955C;&#x50CF;&#x662F;&#x6240;&#x6709;docker&#x955C;&#x50CF;&#x7684;&#x57FA;&#x7840;&#x955C;&#x50CF;</strong>&#xFF0C;&#x5176;&#x4ED6;&#x7684;&#x955C;&#x50CF;&#x76F4;&#x63A5;&#x6216;&#x95F4;&#x63A5;&#x7EE7;&#x627F;scratch&#x3002;</p>
<h1 id="dockerfile&#x7684;&#x4E00;&#x4E9B;&#x89C4;&#x8303;&#x3002;"><a name="dockerfile&#x7684;&#x4E00;&#x4E9B;&#x89C4;&#x8303;&#x3002;" class="anchor-navigation-ex-anchor" href="#dockerfile&#x7684;&#x4E00;&#x4E9B;&#x89C4;&#x8303;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>4. Dockerfile&#x7684;&#x4E00;&#x4E9B;&#x89C4;&#x8303;&#x3002;</h1>
<ol>
<li>&#x6BCF;&#x6761;&#x4FDD;&#x7559;&#x5B57;&#x6307;&#x4EE4;&#x90FD;&#x5FC5;&#x987B;&#x4E3A;&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x4E14;&#x540E;&#x9762;&#x8981;&#x8DDF;&#x968F;&#x81F3;&#x5C11;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x3002;</li>
<li>&#x6307;&#x4EE4;&#x6309;&#x7167;&#x4ECE;&#x4E0A;&#x5230;&#x4E0B;&#xFF0C;&#x987A;&#x5E8F;&#x6267;&#x884C;&#x3002;</li>
<li>#&#x8868;&#x793A;&#x6CE8;&#x91CA;</li>
<li>&#x6BCF;&#x6761;&#x6307;&#x4EE4;&#x90FD;&#x4F1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x955C;&#x50CF;&#x5C42;&#xFF0C;&#x5E76;&#x5BF9;&#x955C;&#x50CF;&#x8FDB;&#x884C;&#x63D0;&#x4EA4;&#x3002;</li>
</ol>
<h1 id="docker-build-&#x6267;&#x884C;dockerfile&#x7684;&#x5927;&#x81F4;&#x6D41;&#x7A0B;&#x3002;"><a name="docker-build-&#x6267;&#x884C;dockerfile&#x7684;&#x5927;&#x81F4;&#x6D41;&#x7A0B;&#x3002;" class="anchor-navigation-ex-anchor" href="#docker-build-&#x6267;&#x884C;dockerfile&#x7684;&#x5927;&#x81F4;&#x6D41;&#x7A0B;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>5. Docker build &#x6267;&#x884C;Dockerfile&#x7684;&#x5927;&#x81F4;&#x6D41;&#x7A0B;&#x3002;</h1>
<ol>
<li>docker&#x4ECE;&#x57FA;&#x7840;&#x955C;&#x50CF;&#x8FD0;&#x884C;&#x4E00;&#x4E2A;&#x5BB9;&#x5668;&#x3002;</li>
<li>&#x6267;&#x884C;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x5E76;&#x5BF9;&#x5BB9;&#x5668;&#x4F5C;&#x51FA;&#x4FEE;&#x6539;&#x3002;</li>
<li>&#x6267;&#x884C;&#x7C7B;&#x4F3C;docker commit&#x7684;&#x64CD;&#x4F5C;&#x63D0;&#x4EA4;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x955C;&#x50CF;&#x5C42;&#x3002;</li>
<li>docker&#x518D;&#x57FA;&#x4E8E;&#x521A;&#x63D0;&#x4EA4;&#x7684;&#x955C;&#x50CF;&#x8FD0;&#x884C;&#x4E00;&#x4E2A;&#x65B0;&#x5BB9;&#x5668;&#x3002;</li>
<li>&#x6267;&#x884C;dockerfile&#x4E2D;&#x7684;&#x4E0B;&#x4E00;&#x6761;&#x6307;&#x4EE4;&#x76F4;&#x5230;&#x6240;&#x6709;&#x6307;&#x4EE4;&#x90FD;&#x6267;&#x884C;&#x5B8C;&#x6210;&#x3002;</li>
</ol>
<p>&#x4E5F;&#x5C31;&#x662F;docker<strong>&#x6BCF;&#x6B21;&#x6267;&#x884C;&#x4E00;&#x6761;dockfile&#x7684;&#x6307;&#x4EE4;&#x90FD;&#x4F1A;&#x5F62;&#x6210;&#x4E00;&#x4E2A;&#x65B0;&#x7684;&#x955C;&#x50CF;&#x5C42;&#xFF0C;&#x76F4;&#x5230;&#x6240;&#x6709;&#x6307;&#x4EE4;&#x90FD;&#x6267;&#x884C;&#x5B8C;&#x6210;</strong>&#x3002;</p>
<h1 id="dockerfile&#x7684;&#x4E00;&#x4E9B;&#x4FDD;&#x7559;&#x5B57;&#x6307;&#x4EE4;&#x3002;"><a name="dockerfile&#x7684;&#x4E00;&#x4E9B;&#x4FDD;&#x7559;&#x5B57;&#x6307;&#x4EE4;&#x3002;" class="anchor-navigation-ex-anchor" href="#dockerfile&#x7684;&#x4E00;&#x4E9B;&#x4FDD;&#x7559;&#x5B57;&#x6307;&#x4EE4;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>6. Dockerfile&#x7684;&#x4E00;&#x4E9B;&#x4FDD;&#x7559;&#x5B57;&#x6307;&#x4EE4;&#x3002;</h1>
<p>&#x6BCF;&#x6761;&#x4FDD;&#x7559;&#x5B57;&#x6307;&#x4EE4;&#x90FD;&#x5FC5;&#x987B;&#x4E3A;&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x4E14;&#x540E;&#x9762;&#x8981;&#x8DDF;&#x968F;&#x81F3;&#x5C11;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x3002;</p>
<ul>
<li><strong>FROM  </strong>&#x5F53;&#x524D;&#x65B0;&#x955C;&#x50CF;&#x662F;&#x57FA;&#x4E8E;&#x54EA;&#x4E2A;&#x955C;&#x50CF;&#x7684;&#x3002;</li>
<li><strong>MAINTAINER </strong>&#x955C;&#x50CF;&#x7EF4;&#x62A4;&#x8005;&#x7684;&#x59D3;&#x540D;&#x548C;&#x90AE;&#x7BB1;&#x5730;&#x5740;&#x3002;</li>
<li><strong>RUN </strong>&#x5BB9;&#x5668;&#x6784;&#x5EFA;&#x65F6;&#x9700;&#x8981;&#x8FD0;&#x884C;&#x7684;&#x547D;&#x4EE4;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x6267;&#x884C;RUN&#x540E;&#x9762;&#x7684;&#x547D;&#x4EE4;&#x3002;</li>
<li><strong>EXPOSE </strong>&#x5F53;&#x524D;&#x5BB9;&#x5668;&#x5BF9;&#x5916;&#x66B4;&#x9732;&#x51FA;&#x7684;&#x7AEF;&#x53E3;&#xFF0C;&#x6BD4;&#x5982;&#xFF1A;tomcat&#x5BF9;&#x5916;&#x66B4;&#x9732;&#x7684;8080&#x7AEF;&#x53E3;&#x3002;</li>
<li><strong>WORKDIR </strong>&#x6307;&#x5B9A;&#x5728;&#x521B;&#x5EFA;&#x5BB9;&#x5668;&#x540E;&#xFF0C;&#x7EC8;&#x7AEF;&#x9ED8;&#x8BA4;&#x767B;&#x9646;&#x7684;&#x8FDB;&#x6765;&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x6211;&#x4EEC;&#x8FDB;&#x5165;docker&#x5BB9;&#x5668;&#x7684;&#x76EE;&#x5F55;&#x3002;</li>
<li><strong>ENV </strong>&#x7528;&#x6765;&#x5728;&#x6784;&#x5EFA;&#x955C;&#x50CF;&#x8FC7;&#x7A0B;&#x4E2D;&#x8BBE;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x3002;&#x65B9;&#x4FBF;&#x540E;&#x9762;&#x5F15;&#x7528;&#x3002;&#x6BD4;&#x5982;&#xFF1A;ENV MY_PATH /usr/mytest&#x3002;&#x8FD9;&#x4E2A;&#x73AF;&#x5883;&#x53D8;&#x91CF;MY_PATH &#x53EF;&#x4EE5;&#x5728;&#x540E;&#x7EED;&#x7684;&#x4EFB;&#x4F55;&#x6307;&#x4EE4;&#x4E2D;&#x4F7F;&#x7528;&#x3002;&#x6BD4;&#x5982;&#xFF1A;WORKDIR $MY_PATH&#x3002;</li>
<li><p><strong>ADD </strong>&#x5C06;&#x5BBF;&#x4E3B;&#x673A;&#x76EE;&#x5F55;&#x4E0B;&#x7684;&#x6587;&#x4EF6;&#x62F7;&#x8D1D;&#x8FDB;&#x955C;&#x50CF;&#x4E14;ADD&#x547D;&#x4EE4;&#x4F1A;&#x81EA;&#x52A8;&#x5904;&#x7406;URL&#x548C;&#x89E3;&#x538B;tar&#x538B;&#x7F29;&#x5305;&#x3002;</p>
</li>
<li><p><strong>COPY  </strong>&#x7C7B;&#x4F3C;ADD&#xFF0C;&#x62F7;&#x8D1D;&#x6587;&#x4EF6;&#x548C;&#x76EE;&#x5F55;&#x5230;&#x955C;&#x50CF;&#x4E2D;&#x3002;&#x4F46;&#x662F;&#x4E0D;&#x4F1A;&#x89E3;&#x538B;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x5904;&#x7406;URL&#xFF0C;&#x5355;&#x7EAF;&#x7684;&#x62F7;&#x8D1D;&#x3002;</p>
</li>
<li><p><strong>VOLUME</strong>  &#x5BB9;&#x5668;&#x6570;&#x636E;&#x5377;&#xFF0C;&#x7528;&#x4E8E;&#x6570;&#x636E;&#x4FDD;&#x5B58;&#x548C;&#x6301;&#x4E45;&#x5316;&#x5DE5;&#x4F5C;&#x3002;</p>
</li>
<li><p><strong>CMD  </strong>&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x5BB9;&#x5668;&#x542F;&#x52A8;&#x65F6;&#x8981;&#x8FD0;&#x884C;&#x7684;&#x547D;&#x4EE4;&#x3002;Dockerfile &#x4E2D;&#x53EF;&#x4EE5;&#x6709;&#x591A;&#x4E2A; CMD &#x6307;&#x4EE4;&#xFF0C;&#x4F46;&#x53EA;&#x6709;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x751F;&#x6548;&#xFF0C;CMD &#x4F1A;&#x88AB; docker run &#x4E4B;&#x540E;&#x7684;&#x53C2;&#x6570;&#x66FF;&#x6362;&#x3002;CMD &#x6307;&#x4EE4;&#x652F;&#x6301;&#x4E09;&#x79CD;&#x683C;&#x5F0F;&#xFF1A;</p>
<pre class="language-"><code>    &#x5728;/bin/sh &#x4E2D;&#x6267;&#x884C;&#xFF0C;&#x63D0;&#x4F9B;&#x7ED9;&#x9700;&#x8981;&#x4EA4;&#x4E92;&#x7684;&#x5E94;&#x7528;&#xFF1A;  CMD <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>&#x547D;&#x4EE4;</span> <span class="token attr-name">&#x53C2;&#x6570;</span><span class="token punctuation">&gt;</span></span> 
    &#x4F7F;&#x7528; exec &#x6267;&#x884C;&#xFF0C;&#x63A8;&#x8350;&#x65B9;&#x5F0F;&#xFF1A; CMD [&quot;&#x53EF;&#x6267;&#x884C;&#x6587;&#x4EF6;&quot;,&quot;&#x53C2;&#x6570;1&quot;,&quot;&#x53C2;&#x6570;2&quot;] 
    &#x5728;&#x6307;&#x5B9A;&#x4E86;ENTRYPOINT&#x6307;&#x4EE4;&#x540E;&#xFF0C;&#x7528;CMD&#x6307;&#x5B9A;&#x9ED8;&#x8BA4;&#x53C2;&#x6570;&#xFF1A; CMD [&quot;&#x53C2;&#x6570;1&quot;,&quot;&#x53C2;&#x6570;2&quot;]
</code></pre></li>
<li><p><strong>ENTRYPOINT</strong> &#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x5BB9;&#x5668;&#x542F;&#x52A8;&#x65F6;&#x8981;&#x8FD0;&#x884C;&#x7684;&#x547D;&#x4EE4;&#x3002;ENTRYPOINT &#x7684;&#x76EE;&#x7684;&#x548C; CMD &#x4E00;&#x6837;&#xFF0C;&#x90FD;&#x662F;&#x5728;&#x6307;&#x5B9A;&#x5BB9;&#x5668;&#x542F;&#x52A8;&#x7A0B;&#x5E8F;&#x53CA;&#x53C2;&#x6570;&#x3002;</p>
</li>
<li><p><strong>ONBUILD  </strong>&#x7236;&#x955C;&#x50CF;&#x5728;&#x88AB;&#x5B50;&#x955C;&#x50CF;&#x7EE7;&#x627F;&#x540E;&#x7236;&#x955C;&#x50CF;&#x7684;onbuild&#x88AB;&#x89E6;&#x53D1;&#x3002;&#x4E5F;&#x5C31;&#x662F;docker build&#x8FD0;&#x884C;Dockerfile&#x65F6;&#xFF0C;&#x5982;&#x679C;&#x8FD9;&#x4E2A;Dockerfile&#x7EE7;&#x627F;&#x67D0;&#x4E2A;&#x7236;Dockerfile&#xFF0C;&#x90A3;&#x7236;Dockerfile&#x7684;ONBUILD&#x540E;&#x9762;&#x7684;&#x6307;&#x4EE4;&#x4F1A;&#x88AB;&#x6267;&#x884C;&#x3002;</p>
</li>
</ul>
<h2 id="&#x4F8B;&#x5B50;1&#xFF1A;&#x4F7F;&#x7528;dockerfile&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;centos&#x955C;&#x50CF;&#x3002;"><a name="&#x4F8B;&#x5B50;1&#xFF1A;&#x4F7F;&#x7528;dockerfile&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;centos&#x955C;&#x50CF;&#x3002;" class="anchor-navigation-ex-anchor" href="#&#x4F8B;&#x5B50;1&#xFF1A;&#x4F7F;&#x7528;dockerfile&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;centos&#x955C;&#x50CF;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>6.1. &#x4F8B;&#x5B50;1&#xFF1A;&#x4F7F;&#x7528;Dockerfile&#x521B;&#x5EFA;&#x81EA;&#x5DF1;&#x7684;centos&#x955C;&#x50CF;&#x3002;</h2>
<p><strong>Dockerfile&#x7684;&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</strong></p>
<pre class="language-"><code>FROM centos
MAINTAINER wk<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>wk@163.com</span><span class="token punctuation">&gt;</span></span>

ENV MYPATH /usr/local
WORKDIR $MYPATH

RUN yum -y install vim
RUN yum -y install net-tools

EXPOSE 80

CMD echo $MYPATH
CMD echo &quot;success--------------ok&quot;
CMD /bin/bash
</code></pre><p>&#x4E0A;&#x9762;&#x7684;&#x5185;&#x5BB9;&#x8868;&#x793A;&#xFF1A;</p>
<ul>
<li>FROM centos &#x8868;&#x793A;&#x8FD9;&#x4E2A;&#x955C;&#x50CF;&#x4ECE;centos&#x6D3E;&#x751F;&#x51FA;&#x6765;&#x7684;&#x3002;</li>
<li>MAINTAINER wk&lt;wk@163.com&gt;  &#x8868;&#x793A;&#x955C;&#x50CF;&#x7EF4;&#x62A4;&#x4EBA;&#x521B;&#x5EFA;&#x4EBA;&#x7684;&#x540D;&#x5B57;&#x548C;&#x90AE;&#x7BB1;&#x3002;</li>
<li><p>ENV MYPATH /usr/local  &#x8868;&#x793A;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;MYPATH&#x7684;&#x503C;&#x662F;/usr/local&#x3002;</p>
</li>
<li><p>WORKDIR $MYPATH  &#x8868;&#x793A;&#x767B;&#x5F55;&#x8FD9;&#x4E2A;&#x955C;&#x50CF;&#x8FD0;&#x884C;&#x7684;&#x5BB9;&#x5668;&#x540E;&#xFF0C;&#x521D;&#x59CB;&#x76EE;&#x5F55;&#x662F;/usr/local&#x3002;$MYPATH&#x662F;&#x5F15;&#x7528;&#x4E0A;&#x9762;&#x7684;MYPATH&#x53D8;&#x91CF;&#x3002;</p>
</li>
<li><p>RUN yum -y install vim  &#x8868;&#x793A;&#x5728;&#x955C;&#x50CF;&#x91CC;&#x9762;&#x8FD0;&#x884C;&#x547D;&#x4EE4;yum -y install vim &#x5B89;&#x88C5;vim&#x547D;&#x4EE4;&#x5DE5;&#x5177;&#x3002;</p>
</li>
<li><p>RUN yum -y install net-tools   &#x8868;&#x793A;&#x5728;&#x955C;&#x50CF;&#x91CC;&#x9762;&#x8FD0;&#x884C;&#x547D;&#x4EE4;yum -y install net-tools &#x5B89;&#x88C5;ifconfig&#x547D;&#x4EE4;&#x5DE5;&#x5177;&#x3002;</p>
</li>
<li><p>EXPOSE 80 &#x8868;&#x793A;&#x5BB9;&#x5668;&#x5BF9;&#x5916;&#x66B4;&#x9732; 80&#x7AEF;&#x53E3;&#x3002;</p>
</li>
<li><p>CMD echo $MYPATH &#x8868;&#x793A;&#x5728;&#x955C;&#x50CF;&#x91CC;&#x9762;&#x8FD0;&#x884C;&#x547D;&#x4EE4;echo $MYPATH  &#x6253;&#x5370;$MYPATH&#x5230;&#x63A7;&#x5236;&#x53F0;&#x3002;</p>
</li>
<li><p>CMD echo &quot;success--------------ok&quot; &#x8868;&#x793A;&#x5728;&#x955C;&#x50CF;&#x91CC;&#x9762;&#x8FD0;&#x884C;&#x547D;&#x4EE4;echo &quot;success--------------ok&quot;   &#x6253;&#x5370;success--------------ok&#x5230;&#x63A7;&#x5236;&#x53F0;&#x3002;</p>
</li>
<li><p>CMD /bin/bash &#x8868;&#x793A;&#x5728;&#x955C;&#x50CF;&#x91CC;&#x9762;&#x8FD0;&#x884C;&#x547D;&#x4EE4;/bin/bash&#x3002;&#x8FD9;&#x4E2A;&#x662F;&#x6700;&#x540E;&#x4E00;&#x5C42;&#x955C;&#x50CF;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x6700;&#x7EC8;&#x7684;&#x955C;&#x50CF;&#x5C42;&#x3002;&#x5BB9;&#x5668;&#x542F;&#x52A8;&#x7684;&#x65F6;&#x5019;&#x4E5F;&#x4F1A;&#x8FD0;&#x884C; /bin/bash &#x547D;&#x4EE4;&#x3002;</p>
</li>
</ul>
<p>&#x4F7F;&#x7528;&#x4E0A;&#x9762;&#x7684;dockerfile&#x751F;&#x6210;&#x955C;&#x50CF;&#xFF0C;&#x547D;&#x4EE4;&#x683C;&#x5F0F;&#x5982;&#x4E0B;&#xFF1A;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x70B9;&#x8868;&#x793A;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x3002;</p>
<pre class="language-"><code>docker build -f Dockerfile&#x6587;&#x4EF6;&#x7684;&#x4F4D;&#x7F6E; -t &#x65B0;&#x7684;&#x955C;&#x50CF;&#x540D;:TAG .
</code></pre><p>&#x8FD0;&#x884C;&#x7684;&#x547D;&#x4EE4;&#x5982;&#x4E0B;&#xFF1A;&#x8868;&#x793A;&#x4F7F;&#x7528;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x4E0B;&#x7684;Dockerfile&#x6587;&#x4EF6;&#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;&#x955C;&#x50CF;mycentos&#xFF0C;TAG&#x662F;1.2&#x3002;</p>
<pre class="language-"><code>docker build -f ./Dockerfile  -t mycentos:1.2 .
</code></pre><p>&#x67E5;&#x770B;&#x955C;&#x50CF;&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x521A;&#x521A;&#x521B;&#x5EFA;&#x7684;&#x955C;&#x50CF;&#x3002;</p>
<pre class="language-"><code>[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mycentos            1.2                 737ea05543bb        2 minutes ago       414MB
</code></pre><p>&#x8FD0;&#x884C;&#x8FD9;&#x4E2A;&#x955C;&#x50CF;&#x4E4B;&#x540E;&#xFF0C;&#x4F7F;&#x7528;pwd&#x547D;&#x4EE4;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5F53;&#x524D;&#x76EE;&#x5F55;&#x662F;&#x955C;&#x50CF;&#x6587;&#x4EF6;&#x5B9A;&#x4E49;&#x7684;WORKDIR&#x76EE;&#x5F55;/usr/local &#xFF1B;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;ifconfig&#x547D;&#x4EE4;&#x4E86;&#x3002;&#x955C;&#x50CF;&#x5B9A;&#x4E49;&#x6210;&#x529F;&#x3002;</p>
<pre class="language-"><code>[root@localhost ~]# docker run -it mycentos:1.2
[root@25e927bac0b7 local]# pwd
/usr/local
[root@25e927bac0b7 local]# ifconfig
eth0: flags=4163<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>UP,BROADCAST,RUNNING,MULTICAST</span><span class="token punctuation">&gt;</span></span>  mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 8  bytes 648 (648.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>UP,LOOPBACK,RUNNING</span><span class="token punctuation">&gt;</span></span>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
</code></pre><h2 id="&#x4F8B;&#x5B50;2&#xFF1A;&#x67E5;&#x770B;&#x955C;&#x50CF;&#x7684;&#x53D8;&#x66F4;&#x5386;&#x53F2;&#x3002;"><a name="&#x4F8B;&#x5B50;2&#xFF1A;&#x67E5;&#x770B;&#x955C;&#x50CF;&#x7684;&#x53D8;&#x66F4;&#x5386;&#x53F2;&#x3002;" class="anchor-navigation-ex-anchor" href="#&#x4F8B;&#x5B50;2&#xFF1A;&#x67E5;&#x770B;&#x955C;&#x50CF;&#x7684;&#x53D8;&#x66F4;&#x5386;&#x53F2;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>6.2. &#x4F8B;&#x5B50;2&#xFF1A;&#x67E5;&#x770B;&#x955C;&#x50CF;&#x7684;&#x53D8;&#x66F4;&#x5386;&#x53F2;&#x3002;</h2>
<p>&#x67E5;&#x770B;&#x955C;&#x50CF;&#x7684;&#x53D8;&#x66F4;&#x5386;&#x53F2;&#xFF0C;&#x547D;&#x4EE4;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code>docker history &#x955C;&#x50CF;&#x540D;:TAG
</code></pre><p>&#x8FD0;&#x884C;&#x5982;&#x4E0B;&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230;docker&#x662F;&#x6BCF;&#x8FD0;&#x884C;&#x4E00;&#x4E2A;dockerfile&#x547D;&#x4EE4;&#x5C31;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x955C;&#x50CF;&#x5C42;&#x3002;</p>
<pre class="language-"><code>[root@localhost ~]# docker history mycentos:1.2
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
737ea05543bb        9 minutes ago       /bin/sh -c #(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;/bin&#x2026;   0B                  
557b24a936f4        9 minutes ago       /bin/sh -c #(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;echo&#x2026;   0B                  
d40c270936e0        9 minutes ago       /bin/sh -c #(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;echo&#x2026;   0B                  
bd2ffd3ab0f6        9 minutes ago       /bin/sh -c #(nop)  EXPOSE 80                    0B                  
d176bcd23491        9 minutes ago       /bin/sh -c yum -y install net-tools             78.5MB              
bb75e3370010        9 minutes ago       /bin/sh -c yum -y install vim                   133MB               
341b26a9810c        20 minutes ago      /bin/sh -c #(nop) WORKDIR /usr/local            0B                  
9411d0c4629a        20 minutes ago      /bin/sh -c #(nop)  ENV MYPATH=/usr/local        0B                  
07524018ec26        20 minutes ago      /bin/sh -c #(nop)  MAINTAINER wk<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>wk@163.com</span><span class="token punctuation">&gt;</span></span>    0B                  
1e1148e4cc2c        3 months ago        /bin/sh -c #(nop)  CMD [&quot;/bin/bash&quot;]            0B                  
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>missing</span><span class="token punctuation">&gt;</span></span>           3 months ago        /bin/sh -c #(nop)  LABEL org.label-schema.sc&#x2026;   0B                  
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>missing</span><span class="token punctuation">&gt;</span></span>           3 months ago        /bin/sh -c #(nop) ADD file:6f877549795f4798a&#x2026;   202MB
</code></pre><h2 id="cmdentrypoint&#x6307;&#x4EE4;&#x7684;&#x533A;&#x522B;&#x3002;"><a name="cmdentrypoint&#x6307;&#x4EE4;&#x7684;&#x533A;&#x522B;&#x3002;" class="anchor-navigation-ex-anchor" href="#cmdentrypoint&#x6307;&#x4EE4;&#x7684;&#x533A;&#x522B;&#x3002;"><i class="fa fa-link" aria-hidden="true"></i></a>6.3. CMD/ENTRYPOINT&#x6307;&#x4EE4;&#x7684;&#x533A;&#x522B;&#x3002;</h2>
<p>&#x6211;&#x4EEC;&#x8FD0;&#x884C;&#x4E00;&#x4E2A;&#x5BB9;&#x5668;&#x7684;&#x547D;&#x4EE4;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code>docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
</code></pre><p>&#x5176;&#x4E2D;[COMMAND] [ARG...] &#x8868;&#x793A;&#x5BB9;&#x5668;&#x542F;&#x52A8;&#x4E4B;&#x540E;&#x8981;&#x8FD0;&#x884C;&#x7684;&#x547D;&#x4EE4;&#x548C;&#x53C2;&#x6570;&#x3002;</p>
<p><strong>Dockerfile&#x4E2D;CMD&#x548C;ENTRYPOINT&#x7684;&#x533A;&#x522B;&#x5982;&#x4E0B;&#xFF1A;</strong></p>
<ul>
<li><p>CMD/ENTRYPOINT  &#x90FD;&#x662F;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x5BB9;&#x5668;&#x542F;&#x52A8;&#x65F6;&#x8981;&#x8FD0;&#x884C;&#x7684;&#x547D;&#x4EE4;&#x3002;&#x4E5F;&#x5C31;&#x662F;&#x4F7F;&#x7528;docker run &#x8FD0;&#x884C;&#x5BB9;&#x5668;&#x7684;&#x65F6;&#x5019;&#x3002;&#x8981;&#x6267;&#x884C;&#x7684;&#x547D;&#x4EE4;[COMMAND] [ARG...] &#x53EF;&#x4EE5;&#x7531;Dockerfile&#x4E2D;CMD&#x6216;&#x8005;ENTRYPOINT &#x6307;&#x5B9A;&#x3002;&#x6BD4;&#x5982;&#xFF1A;tomcat&#x955C;&#x50CF;&#x5C31;&#x6307;&#x5B9A;&#x8FD0;&#x884C;&#x5176;&#x5BB9;&#x5668;&#x7684;&#x65F6;&#x5019;&#x542F;&#x52A8;tomcat&#x3002;</p>
</li>
<li><p>Dockerfile &#x4E2D;&#x53EF;&#x4EE5;&#x6709;&#x591A;&#x4E2A; CMD &#x6307;&#x4EE4;&#xFF0C;&#x4F46;&#x53EA;&#x6709;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x751F;&#x6548;&#x3002;&#x5982;&#x679C;&#x8FD0;&#x884C;&#x5BB9;&#x5668;docker run &#x7684;&#x65F6;&#x5019; [COMMAND] [ARG...] &#x5B58;&#x5728;&#xFF0C;&#x90A3;Dockerfile&#x4E2D;CMD&#x4F1A;&#x88AB;&#x8FD9;&#x4E2A;&#x547D;&#x4EE4;&#x66FF;&#x6362;&#x3002;&#x5C31;&#x4E0D;&#x4F1A;&#x6267;&#x884C;Dockerfile&#x4E2D;&#x7684;CMD&#x6307;&#x5B9A;&#x7684;&#x547D;&#x4EE4;&#x3002;</p>
</li>
<li><p>docker run &#x4E4B;&#x540E;&#x7684;&#x53C2;&#x6570;[COMMAND] [ARG...]&#x4F1A;&#x88AB;&#x5F53;&#x505A;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x7ED9; ENTRYPOINT&#xFF0C;&#x4E4B;&#x540E;&#x5F62;&#x6210;&#x65B0;&#x7684;&#x547D;&#x4EE4;&#x7EC4;&#x5408; &#x3002;</p>
<p>&#x4F8B;&#x5B50;&#xFF1A;&#x5982;&#x679C;centos&#x955C;&#x50CF;Dockerfile &#x4E2D;ENTRYPOINT&#x6307;&#x5B9A;&#x7684;&#x547D;&#x4EE4;&#x662F; ls &#xFF0C;&#x8FD0;&#x884C;centos&#x5BB9;&#x5668;&#x7684;&#x547D;&#x4EE4;&#x662F;docker run  -it centos -l&#xFF0C;&#x4E5F;&#x5C31;&#x662F;[COMMAND] [ARG...]&#x662F;-l &#x3002;&#x7ED3;&#x679C;&#x8FD0;&#x884C;centos&#x5BB9;&#x5668;&#x4E4B;&#x540E;&#x6267;&#x884C;&#x7684;&#x547D;&#x4EE4;&#x662F; ls -l&#x3002;&#x5C31;&#x662F;&#x628A;docker run&#x4E2D;&#x7684;[COMMAND] [ARG...]&#x4F20;&#x9012;&#x7684;&#x503C;&#x4F5C;&#x4E3A;&#x547D;&#x4EE4;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x7ED9;ENTRYPOINT&#x3002;</p>
</li>
</ul>
<h3 id="&#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;"><a name="&#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;" class="anchor-navigation-ex-anchor" href="#&#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;"><i class="fa fa-link" aria-hidden="true"></i></a>6.3.1. &#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</h3>
<ul>
<li>&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;cmd&#x547D;&#x4EE4;&#x7684;Dockerfile &#x3002;</li>
</ul>
<pre class="language-"><code>FROM centos
CMD [ &quot;ls&quot;]
</code></pre><ul>
<li>&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;ENTRYPOINT&#x547D;&#x4EE4;&#x7684;Dockerfile &#x3002;</li>
</ul>
<pre class="language-"><code>FROM centos
ENTRYPOINT [&quot;ls&quot;]
</code></pre><ul>
<li>&#x4EE5;&#x4E0A;&#x9762;&#x7684;2&#x4E2A;Dockerfile &#x521B;&#x5EFA;2&#x4E2A;&#x955C;&#x50CF;&#x3002;mycentoscmd &#x548C;mycentosentrypoint&#x3002;</li>
</ul>
<pre class="language-"><code>[root@localhost ~]# docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
mycentosentrypoint   latest              0a7cbb21686b        20 seconds ago      202MB
mycentoscmd          latest              7fc40a4ef1eb        3 minutes ago       202MB
</code></pre><ul>
<li>&#x8FD0;&#x884C;&#x5BB9;&#x5668;&#x3002;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x6587;&#x4EF6;&#x3002;&#x76F8;&#x5F53;&#x4E8E;&#x767B;&#x5F55;centos&#x8FD0;&#x884C;&#x547D;&#x4EE4;ls&#x3002;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre class="language-"><code>[root@localhost ~]# docker run -it mycentoscmd
anaconda-post.log  dev    home  lib64  mnt  proc    run   srv  tmp    var
bin           etc    lib   media  opt  root    sbin  sys  usr
</code></pre><pre class="language-"><code>[root@localhost ~]# docker run -it mycentosentrypoint
anaconda-post.log  dev    home  lib64  mnt  proc    run   srv  tmp    var
bin           etc    lib   media  opt  root    sbin  sys  usr
</code></pre><ul>
<li>&#x52A0; -l &#x53C2;&#x6570;&#x8FD0;&#x884C;&#x5BB9;&#x5668;&#x3002;&#x4E5F;&#x5C31;&#x662F;[COMMAND] [ARG...]&#x7684;&#x503C;&#x662F;-l&#x3002;&#x8FD9;&#x65F6;&#x5019;mycentoscmd&#x955C;&#x50CF;&#x4F1A;&#x628A;-l&#x5F53;&#x505A;&#x4E00;&#x4E2A;&#x547D;&#x4EE4;&#xFF0C;&#x4F1A;&#x62A5;&#x9519;&#xFF1B;mycentosentrypoint&#x4F1A;&#x5217;&#x51FA;&#x6587;&#x4EF6;&#x76F8;&#x5F53;&#x4E8E;&#x767B;&#x5F55;centos&#x8FD0;&#x884C;&#x547D;&#x4EE4;ls -l&#x3002;&#x5982;&#x4E0B;&#xFF1A;</li>
</ul>
<pre class="language-"><code>[root@localhost ~]# docker run -it mycentosentrypoint -l
total 12
-rw-r--r--.   1 root root 12076 Dec  5 01:37 anaconda-post.log
lrwxrwxrwx.   1 root root     7 Dec  5 01:36 bin -&gt; usr/bin
drwxr-xr-x.   5 root root   360 Mar 16 17:32 dev
drwxr-xr-x.   1 root root    66 Mar 16 17:32 etc
drwxr-xr-x.   2 root root     6 Apr 11  2018 home
lrwxrwxrwx.   1 root root     7 Dec  5 01:36 lib -&gt; usr/lib
lrwxrwxrwx.   1 root root     9 Dec  5 01:36 lib64 -&gt; usr/lib64
drwxr-xr-x.   2 root root     6 Apr 11  2018 media
drwxr-xr-x.   2 root root     6 Apr 11  2018 mnt
drwxr-xr-x.   2 root root     6 Apr 11  2018 opt
dr-xr-xr-x. 205 root root     0 Mar 16 17:32 proc
dr-xr-x---.   2 root root   114 Dec  5 01:37 root
drwxr-xr-x.  11 root root   148 Dec  5 01:37 run
lrwxrwxrwx.   1 root root     8 Dec  5 01:36 sbin -&gt; usr/sbin
drwxr-xr-x.   2 root root     6 Apr 11  2018 srv
dr-xr-xr-x.  13 root root     0 Mar 12 02:00 sys
drwxrwxrwt.   7 root root   132 Dec  5 01:37 tmp
drwxr-xr-x.  13 root root   155 Dec  5 01:36 usr
drwxr-xr-x.  18 root root   238 Dec  5 01:36 var
[root@localhost ~]# docker run -it mycentoscmd -l
docker: Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused &quot;exec: \&quot;-l\&quot;: executable file not found in $PATH&quot;: unknown.
</code></pre>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="8、容器数据卷-持久化文件或目录.html" class="navigation navigation-prev " aria-label="Previous page: 8、容器数据卷(持久化文件或目录)">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="10、创建自己的tomcat镜像.html" class="navigation navigation-next " aria-label="Next page: 10、创建自己的tomcat镜像">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"9、dockerfile","level":"1.3.9","depth":2,"next":{"title":"10、创建自己的tomcat镜像","level":"1.3.10","depth":2,"path":"docker/10、创建自己的tomcat镜像.md","ref":"docker/10、创建自己的tomcat镜像.md","articles":[]},"previous":{"title":"8、容器数据卷(持久化文件或目录)","level":"1.3.8","depth":2,"path":"docker/8、容器数据卷-持久化文件或目录.md","ref":"docker/8、容器数据卷-持久化文件或目录.md","articles":[]},"dir":"ltr"},"config":{"plugins":["donate","copy-code-button","expandable-chapters","prism","prism-themes","-highlight","anchor-navigation-ex","-sharing","sharing-plus"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{"css":["prism-themes/themes/prism-duotone-dark.css"]},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"/gitbook的使用/Donate/alipay.jpg","alipayText":"支付宝打赏","button":"捐赠","title":"如果您觉得有用，请我喝杯水。","wechat":"/gitbook的使用/Donate/wechat.png","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"prism-themes":{},"copy-code-button":{},"sharing":{"qq":true,"all":["weibo","douban","google","line","hatenaBookmark","instapaper","viber","vk","whatsapp","stumbleupon","messenger"],"douban":false,"facebook":true,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":true},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"wk","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"王坤个人博客","language":"zh-hans","links":{"sidebar":{"我的博客地址":"https://my.oschina.net/kunBlog"}},"gitbook":"3.2.3","description":"王坤个人博客"},"file":{"path":"docker/9、dockerfile.md","mtime":"2020-02-01T04:13:06.454Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-01T11:40:27.319Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

